<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("modelConfigPath", "billing");
%>
<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style >
	#outStockInfoCopy{display:none}
	td input{height:21px; width:98%;border:none;}
	td{height:21px;padding: 2px 2px !important;text-align:center }
	#area{
		height:302px;
		width:1097px;
		overflow-y:auto; 
		overflow-x:hidden; 
	}
</style>
<ul class="nav nav-tabs nav-tabs-component " style="margin-bottom: 0px;">
	<li class="active"><a href="#category-tab" data-toggle="tab" >订单详情</a></li>
	<li><a href="#billingRecord-tab" data-toggle="tab" >订单操作记录</a></li>
</ul>
<div class="tab-content">
	<div class="tab-pane active" id="category-tab">
		<t:panel cssClass="panel-flat form-detailed" customBody="true" customHead="true">
			<div class="detailed-navbar-content panel-body">
				<t:form modelAttribute="billing" action="/billing/billing/checkSave" method="post" cssClass="form-horizontal">
					<div class="hide">
						 <t:hidden path="billingId"/>
		 				 <t:hidden path="deleteMark"/>	
		 				 <t:hidden path="createUserName"/>
				 		 <t:hidden path="createUserId"/>
				 		 <t:hidden path="createDate"/>
				 		 <t:hidden path="shopId"/>
				 		 <t:hidden path="confirm"/>
					</div>
		            <t:formgroup>
		            	<t:label path="billingNo" cssClass="col-sm-1 col-xs-1" />
		       			<t:input readonly="true" path="billingNo" colClass="col-sm-2 col-xs-2" />
		                <t:label path="customerId" cssClass="col-sm-1 col-xs-1" />
		                <t:select2 path="customerId" placeholder="请填写客户" allowClear="true" colClass="col-sm-2 col-xs-2"></t:select2>
		                
		            	<t:label path="deliveryDate" cssClass="col-sm-1 col-xs-1" />
		                <t:date  path="deliveryDate" colClass="col-sm-2 col-xs-2"></t:date>
		                <t:label path="businessId" cssClass="col-sm-1 col-xs-1" />
		                <t:select2 path="businessId" placeholder="业务员" allowClear="true" colClass="col-sm-2 col-xs-2"></t:select2>
		            </t:formgroup>
		            <t:formgroup>
		            	<t:label path="billingMoney" cssClass="col-sm-1 col-xs-1" />
						<t:input path="billingMoney" colClass="col-sm-2 col-xs-2" />
		                <t:label path="discount" cssClass="col-sm-1 col-xs-1" />
						<t:input path="discount" colClass="col-sm-2 col-xs-2" />
						
		            	<t:label path="comment" cssClass="col-sm-1 col-xs-1" />
						<t:textarea path="comment" colClass="col-sm-5 col-xs-5" />
		            </t:formgroup>
		            <div id="area">
		            <table  class="cntable table table-bordered dataTable table-billing">
			            <thead>
				            <tr class="success">
				            	<th style="width:80px">序号</th>
				            	<th style="width:150px">商品编码</th>
		            			<th style="width:200px">商品名称</th>
				            	<th style="width:150px">规格</th>
				            	<th style="width:100px">单位</th>
				            	<th style="width:100px">数量</th>
				            	<th style="width:100px">单价</th>
				            	<th>小计</th>
				            </tr>
			            </thead>
			            
			            <tbody id="outStockInfo">
			            
							<c:set var="sequence"  value="0"/>
							<c:if test="${type eq 'modify' || type eq 'check'}" >
								<c:forEach var="outStockShow" items="${billing.outStock.outStockShows}">
									<c:forEach var="outStockCollocation" items="${outStockShow.outStockCollocations}" >
										
										<tr id="outStockCollocation_${sequence}">
											<td style="display:none"><input id="collocationId_${sequence}" name="collocationId" type="text" value="${outStockCollocation.collocationId}"/></td>
											<td style="display:none"><input id="cargoId_${sequence}" name="cargoId" type="text" value="${outStockShow.cargoId}"/></td>
											<td name="index">${sequence +1}</td>					
							            	<td><input style="ime-mode:disabled" readonly="true" id="cargoNo_${sequence}" name="cargoNo" type="text" value="${outStockShow.cargo.cargoNo}"></input></td>
							            	<td><input style="ime-mode:disabled" readonly="true" id="cargoName_${sequence}" name="cargoName" type="text" value="${outStockShow.cargo.cargoName}"/></td>
							            	<c:if test="${outStockCollocation.collocation.propertyNameTwo==null }">
							            		<td><input style="ime-mode:disabled" readonly="true" id="propertyName_${sequence}" name="propertyName" type="text" value="${outStockCollocation.collocation.propertyNameOne}"/></td>
							            	</c:if>
							            	<c:if test="${outStockCollocation.collocation.propertyNameTwo!=null }">
							            		<td><input style="ime-mode:disabled" readonly="true" id="propertyName_${sequence}" name="propertyName" type="text" value="${outStockCollocation.collocation.propertyNameOne}/${outStockCollocation.collocation.propertyNameTwo}"/></td>
							            	</c:if>
							            	<td ><input style="ime-mode:disabled" readonly="true" id="unit_${sequence}" name="unit" type="text" value="${outStockShow.cargo.unit}"/></td>
											<td><input style="ime-mode:disabled" readonly="true" onkeyup="return ValidateNumber(this,value)" id="collocationNum_${sequence}"  name="collocationNum" type="text" value="${outStockCollocation.collocationNum}"/></td>
											<td><input style="ime-mode:disabled" readonly="true" onkeyup="return ValidateNumber(this,value)" id="realPrice_${sequence}" name="realPrice" type="text" value="${outStockCollocation.realPrice}"/></td>
											<td><input style="ime-mode:disabled" readonly="true" id="subtotal_${sequence}" name="subtotal" type="text" value="${outStockCollocation.realPrice*outStockCollocation.collocationNum}"/></td>
										</tr>
										<c:set var="sequence"  value="${sequence +1}"/>
									</c:forEach>
								</c:forEach>
								
							</c:if>
						</tbody>
		            </table>
					</div>
				</t:form>
			</div>
			<c:if test="${type != 'check'}" >
				<t:panelFoot headingBtnCssClass="heading-btn pull-right-important">
					<t:button icon="icon-floppy-disk" onclick="billingClose()" laddaType="progress" cssClass="btn-info" csize="sm">作废</t:button>
					<c:if test="${t_openLocation != 'returnOfCargo'}" >
						<t:button icon="icon-floppy-disk" onclick="editData()" laddaType="progress" cssClass="btn-info" csize="sm">编辑</t:button>
					</c:if>
					<t:button icon="icon-floppy-disk" onclick="saveData()" laddaType="progress" cssClass="btn-info" csize="sm">通过</t:button>
				</t:panelFoot>
			</c:if>
		</t:panel>
	</div>
	<div class="tab-pane" id="billingRecord-tab">
		<iframe id="billingRecordIframe" name="billingRecordIframe" scrolling="auto" frameborder="0"
				scrolling="yes" width="100%" height="100%"  data-src="<c:url value='/billing/billingRecord/index?billingId=${billing.billingId }'/>">
        </iframe>
	</div>
</div>
<script type="text/javascript">

$(function(){
	
	iframeLazyOpen();
	tabpaneResize();

})

function iframeLazyOpen(){
	$(".nav.nav-tabs.nav-tabs-component li a").click(function(){
		var iframeTab = $(this).attr("href");
		var iframeId = iframeTab.substring(0,iframeTab.indexOf("-")) + "Iframe";
		$(iframeId).attr("src",$(iframeId).attr("data-src"));
	});
}

function tabpaneResize(){
	$(".tab-pane").height($(window).height() - 50);
	
	$(window).bind("resize",function(){$(".tab-pane").height($(window).height() - 50)});
	
}

function ValidateNumber(e, pnumber){
	if (!/^\d+[.]?\d*$/.test(pnumber))
	{
	e.value = /^\d+[.]?\d*/.exec(e.value);
	}else{
		
 	}
	return false;
}
function reload(){
	location.reload();
}


function saveData(lBtn){
	var isRepetition = false;
	var collocationIds=[];
	$("input[name='collocationId']").each(function(){
		collocationIds.push({
			id:$(this).val(),
			text:$(this).val()
		})
	});

	for(var i=0;i<collocationIds.length;i++){
		console.log(collocationIds[i].id);
		for(var j=i+1;j<collocationIds.length;j++){
			if(collocationIds[i].id==collocationIds[j].id){
				isRepetition=true;
			}
		}
	}
	
	var isSave=false;
	$("input[name='collocationId']").each(function(){
		if($(this).val()!=null && $(this).val() != ""){
			isSave=true;
		}
						
	});
	if(!isSave){
		$.showTips("请选择开单货品！",1000,"warning");
		return;
	}

	if (!$("form:first").valid()){
		return;
	}
	lBtn.start();
	$("form:first").submit();
}	

function billingClose(){
	var id=$("#billingId").val();
	if(id!=null&&id!=""){
		var url = $.getVirtualPath()+"/billing/billing/checkBillingState?key="+id;
        var msg =  $.getText(url);
    	if("banClose"==msg){
       		$.showTips("此订单不允许关闭！",1000,"warning");
       	}else{
       		confirm("是否确认关闭订单？",function(result){
    			if(result){
    				var url = $.getVirtualPath()+"/billing/billing/closeBillingByKey";
    			    var msg =  $.getJsonPost(url,"key="+id);
    			    $.showTips(msg.message,1000,msg.resultType);
    			    $("form:first").submit();
    			}
    		});
       	}
	}
}

function editData(){
	var id=$("#billingId").val();
	if(id!=null&&id!=""){
		top.openModal("/billing/billing/detailed?key="+id+"&type="+"modify"+"&level=${t_level}"+"&check="+"check","billingEdit_form","订单详情-修改",1100,550);
	}
}
</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formtags.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formbuttons.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>